import 'dart:io';

import 'package:animal/constant/color.dart';
import 'package:animal/constant/length.dart';
import 'package:animal/socket/socket_client.dart';
import 'package:animal/ui/login/page/login_page.dart';
import 'package:animal/utils/screen_util.dart';
import 'package:animal/utils/sputils/sp_config.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:uuid/uuid.dart';


///开始页面
class StartPage extends StatefulWidget {
  const StartPage({Key? key}) : super(key: key);

  @override
  State<StartPage> createState() => _StartPageState();
}

class _StartPageState extends State<StartPage> {
  @override
  Widget build(BuildContext context) {
    ScreenUtil.instance =
        ScreenUtil(width: KLength.designWidth, height: KLength.designHeight)
          ..init(context);
    nextPage();
    return Scaffold(
      backgroundColor: KColorConstant.white,
      body: Image.asset("images/start.png", fit: BoxFit.cover),
    );
  }

  nextPage() {
    Future.delayed(const Duration(milliseconds: 3150), () {
      // if (SpConfig().getUserToken() == "") {
      //   Get.off(LoginPage());
      // } else {
      //   Get.off(HomePage());
      // }
      Get.off(const LoginPage());
      // Get.off(const HomeIndexPage());
    });
  }

  @override
  void initState(){
    super.initState();
    _getDeviceInfo();
  }

  void _getDeviceInfo() async {
    Uuid uuid = const Uuid();
    debugPrint(uuid.v4());
    //系统信息
    DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
    if (Platform.isIOS) {
      debugPrint('IOS设备：');
      IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
      // SpConfig().setAndroidProduct(iosInfo);
    } else if (Platform.isAndroid) {
      AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
      SpConfig().setAndroidProduct(androidInfo.androidId);
      SpConfig().setDeviceVersion("${androidInfo.brand} ${androidInfo.model}");
      SpConfig().setAppVersion("${androidInfo.version.sdkInt}");
      debugPrint('Android设备');
      debugPrint('${androidInfo.androidId}');
      debugPrint('${androidInfo.bootloader}');
      debugPrint('${androidInfo.id}');
      debugPrint('${androidInfo.display}');
    }
  }
}

